const request = require('./request')
const getapi = require('../api/request')
const formarTime = (time) => {
  const date = new Date(time)
  console.log(date)
}

// 格式化音频时间
const formarSongsTime = (duration) => {
  const audiodurations = duration / 1000
  let minute = Math.floor(audiodurations / 60)
  let second = Math.floor((audiodurations / 60 - minute) * 60)
  minute = minute < 10 ? `0${minute}` : (minute + '')
  second = second < 10 ? `0${second}` : (second + '')
  return minute + ':' + second
}
// 音乐播放
const playSong = (e) => {
  return new Promise((resolve, reject) => {
    Promise.all([request.get('/song/url', { id: e }), getapi.songDetail(e)])
      .then((res) => {
        resolve(res)
      })
  })
}

module.exports = {
  formarTime,
  formarSongsTime,
  playSong
}
